package com.example.myapplication;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class BlankFragment extends Fragment {
    RecyclerView recyclerView;

    Adapter2 adapter;

    Context context;
    @SuppressLint("MissingInflatedId")
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.activity_adapter2, container, false);
        // Inflate the layout for this fragment

        recyclerView= view.findViewById(R.id.recycler4);

        List<Map<String,Object>> list=new ArrayList<>();

        int[] avtar={R.drawable.avtar1,R.drawable.avtar2,R.drawable.avtar3,R.drawable.avtar4,R.drawable.avtar5,R.drawable.avtar6,R.drawable.avtar7,R.drawable.avtar8};

        String[] username={"小张","小王","小李","小红","小军","小东","小周","小徐"};

        String[] messages={"在干嘛呢？","你好你好","我是小李，你好","小红驾到" ,"你从事什么工作？","我是东哥","你好你好，我是小周","刚才在路上看到你了"};

        for(int i=0;i<username.length;i++){
            Map<String,Object> map=new HashMap<>();
            map.put("username",username[i]);
            map.put("avatar",avtar[i]);
            map.put("message",messages[i]);
            list.add(map);
        }

        context=getContext();

        adapter= new Adapter2(getContext(),list);

        LinearLayoutManager manager=new LinearLayoutManager(getContext());

        manager.setOrientation(RecyclerView.VERTICAL);

        recyclerView.setAdapter(adapter);

        recyclerView.setLayoutManager(manager);

        return view;
    }
}